home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
- +
- + LEDA 2.1.1 11-15-1991
- +
- +
- + dictionary.h
- +
- +
- + Copyright (c) 1991 by Max-Planck-Institut fuer Informatik
- + Im Stadtwald, 6600 Saarbruecken, FRG
- + All rights reserved.
- +
- *******************************************************************************/
-
-
-
-
-
- //------------------------------------------------------------------------------
- //
- // dictionary (data structure: red black trees)
- //
- // Stefan Naeher (1989)
- //
- //------------------------------------------------------------------------------
-
- #ifndef DICTIONARYH
- #define DICTIONARYH
-
- #ifndef RBTREEH
- #include <LEDA/rb_tree.h>
- #endif
-
- typedef rb_tree_node* dic_item;
-
- #define dictionary(keytype,infotype) name3(keytype,infotype,dictionary)
-
-
- #define dictionarydeclare2(keytype,infotype)\
- \
- struct dictionary(keytype,infotype) : public rb_tree {\
- \
- int cmp(ent& x, ent& y) const { return compare(*(keytype*)&x,*(keytype*)&y); }\
- void clear_key(ent& x) const { Clear(*(keytype*)&x); }\
- void clear_inf(ent& x) const { Clear(*(infotype*)&x); }\
- void copy_key(ent& x) const { Copy(*(keytype*)&x); }\
- void copy_inf(ent& x) const { Copy(*(infotype*)&x); }\
- \
- int defined(keytype y) const { return rb_tree::member(Ent(y)); }\
- dic_item lookup(keytype y) const { return rb_tree::lookup(Ent(y)); }\
- infotype& info(dic_item it) { return *(infotype*)&(rb_tree::info(it)); } \
- void change_inf(dic_item it, infotype i) { info(it) = i; }\
- \
- dic_item insert(keytype y,infotype x)\
- { return rb_tree::insert(Ent(y),Ent(x)); } \
- \
- void del(keytype y) { rb_tree::del(Ent(y)); } \
- void del_item(dic_item it) { del(key(it)); } \
- keytype key(dic_item it) const { return keytype(rb_tree::key(it)); }\
- infotype inf(dic_item it) const { return infotype(rb_tree::info(it)); } \
- infotype access(keytype k) const { return inf(lookup(k));}\
- \
- dictionary(keytype,infotype)& operator =(const dictionary(keytype,infotype)& D)\
- { return (dictionary(keytype,infotype)&)rb_tree::operator=(rb_tree((rb_tree&) D)); }\
- \
- dictionary(keytype,infotype)() {}\
- dictionary(keytype,infotype)(const dictionary(keytype,infotype)& D) :\
- rb_tree((rb_tree&) D) {}\
- ~dictionary(keytype,infotype)() { clear(); }\
- } ;
-
-
- // ----------------------------------------------------------------
- // iteration
- // ----------------------------------------------------------------
-
- #define forall_dic_items(i,D) for(i = (D).first_item(); i; i=(D).next_item(i))
-
- #endif
-